<html>
<head><meta charset="utf-8"><title>higher-ranked trait bounds · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html">higher-ranked trait bounds</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239760014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239760014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239760014">(May 21 2021 at 14:30)</a>:</h4>
<p>i keep getting tripped up by the term "higher-ranked trait bounds". like what is being ranked higher than what? some of the text in the reference makes it sound like it's a universal quantifier over lifetimes. is that a correct interpretation?</p>



<a name="239760070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239760070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239760070">(May 21 2021 at 14:31)</a>:</h4>
<p>yes</p>



<a name="239760115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239760115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239760115">(May 21 2021 at 14:31)</a>:</h4>
<p>it's a trait bound of the form <code>T: for&lt;'a&gt; Trait&lt;'a&gt;</code></p>



<a name="239760140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239760140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239760140">(May 21 2021 at 14:31)</a>:</h4>
<p>the <code>for&lt;'a&gt;</code> is a universal quantifier</p>



<a name="239760476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239760476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239760476">(May 21 2021 at 14:33)</a>:</h4>
<p>thanks. the opening sentence of the section is "Type bounds may be higher ranked over lifetimes.", so i'm not sure exactly what they mean by "type bounds" (trait bounds? lifetime bounds?), or whether "over" means "ranging over" or "above", etc.</p>



<a name="239761003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239761003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239761003">(May 21 2021 at 14:36)</a>:</h4>
<p>You can also write <code>for&lt;'b&gt; T: 'b</code></p>



<a name="239761071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239761071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239761071">(May 21 2021 at 14:36)</a>:</h4>
<p>I think by "type bounds" it means any bound (trait or lifetime) where the bound thing is a type</p>



<a name="239761451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239761451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239761451">(May 21 2021 at 14:39)</a>:</h4>
<p>oh, <a href="https://doc.rust-lang.org/nomicon/hrtb.html">https://doc.rust-lang.org/nomicon/hrtb.html</a> makes it sound like higher-ranked trait bounds are to bind a lifetime in a function signature to a universal quantifier so the surrounding item doesn't have to have a named lifetime parameter. is that right?</p>



<a name="239761745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239761745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239761745">(May 21 2021 at 14:40)</a>:</h4>
<p>yeah, that would be using them like this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">f</span><span class="p">(</span><span class="n">callback</span>: <span class="nc">for</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="k">fn</span><span class="p">(</span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">u16</span><span class="p">))</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="239761764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239761764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239761764">(May 21 2021 at 14:41)</a>:</h4>
<p>but that's not really a trait bound</p>



<a name="239761784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/higher-ranked%20trait%20bounds/near/239761784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/higher-ranked.20trait.20bounds.html#239761784">(May 21 2021 at 14:41)</a>:</h4>
<p>we might be missing good terminology for this</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>